package com.ruibang.glass.etl.handler.sl;


import com.gitee.Jmysy.binlog4j.core.BinlogEvent;
import com.gitee.Jmysy.binlog4j.core.IBinlogEventHandler;
import com.gitee.Jmysy.binlog4j.springboot.starter.annotation.BinlogSubscriber;
import com.ruibang.glass.etl.entity.SlARackBindRecord;
import com.ruibang.glass.etl.mapper.SlARackBindDetailMapper;
import com.ruibang.glass.etl.mapper.SlARackBindRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;

@BinlogSubscriber(clientName = "sl")
public class SLBindRecordBinlogEventHandler implements IBinlogEventHandler<SlARackBindRecord> {

    @Autowired
    private SlARackBindRecordMapper slARackBindRecordMapper;
    @Override
    public void onInsert(BinlogEvent<SlARackBindRecord> event) {
        if(1 > slARackBindRecordMapper.insert(event.getData())){
            System.out.println("sl_a_rack_bind_record 插入数据失败:" + event.getData());
        }else
            System.out.println("sl_a_rack_bind_record 插入数据成功");
    }

    @Override
    public void onUpdate(BinlogEvent<SlARackBindRecord> event)  {
        if(1 > slARackBindRecordMapper.updateById(event.getData())){
            System.out.println("sl_a_rack_bind_record 更新数据失败:" + event.getData());
            onInsert(event);
        }else
            System.out.println("sl_a_rack_bind_record 更新数据成功");
    }

    @Override
    public void onDelete(BinlogEvent<SlARackBindRecord> event) {

        if(1 > slARackBindRecordMapper.deleteById(event.getData())){
            System.out.println("sl_a_rack_bind_record 删除数据失败:" + event.getData());
        }else
            System.out.println("sl_a_rack_bind_record 删除数据成功");
    }

    @Override
    public boolean isHandle(String database, String table) {
        return database.equals("cold1_bc2mes") && table.equals("sl_a_rack_bind_record");
    }
}
